$(document).ready(function(){
  
}); 
button_update_onclick = function (){
	if (isLegal() == 0) {
        return;
    }  
//	efgrid.submitForm( "ef_grid_result", "ZM","ZMCS70","update",true);
	//以下为行增有重复性校验
	var info = getSCZXEiInfos("ZMCS70","ef_grid_result");
	if (null != info) { 
		EiCommunicator.send("ZMCS70", "validate", info, validate_callback);
	}
}
button_insert_onclick = function (){
	if (isLegal() == 0) {
        return;
    }
	
//	efgrid.submitForm( "ef_grid_result", "ZM","ZMCS70","insert",true);
	var info = getSCZXEiInfos("ZMCS70","ef_grid_result");
	if (null != info) { 
		EiCommunicator.send("ZMCS70", "validate", info, validate_callback);
	}
}
button_delete_onclick = function (){
	if (isLegal() == 0) {
        return;
    }
	efgrid.submitForm( "ef_grid_result", "ZM","ZMCS70","delete",true);
}
var validate_callback={
		onSuccess:function(eiInfo){
			if(eiInfo.getStatus()==-1){
				EFAlert("操作失败，原因："+eiInfo.getMsg());
			}else{
/*				 efwindow.hide();
				 var grid = efgrid.getGridObject("ef_grid_result");
				 grid.refresh(eiInfo);*/
				var oper="insert";
				if(eiInfo.get("efCurButtonEname")=="UPDATE"){
					oper="update";
				}
				efgrid.submitForm("ef_grid_result", "ZM", "ZMCS70",oper, true);
			}
		},
		onFail:function(eMsg)
		{
			EFAlert("操作失败，原因："+eMsg); 
		}
}
/*
判断查询条件项是否合法
*/
function isLegal() {
	  var grid = efgrid.getGridObject("ef_grid_result");
	  var rows = grid.getCheckedRows();
	  if(rows.length<=0){
	  	  alert("请至少选择一条数据！");
	      return 0;
	  }
      for(var i=0;i<rows.length;i++)
      {
    	var fdEndTime=grid.getCellValue(rows[i], 5, TYPE_DATA);
    	if ("00:00"==fdEndTime)
        {
            EFAlert("结束时间不允许输入00:00!");
            return 0;
        }
      } 
} 
 
setAuth = function(row_index, col_index, flage){
	var grid = efgrid.getGridObject("ef_grid_result");
	if(flage){
		grid.setCellValue(row_index, col_index, '1',TYPE_DATA);
	}else{
		grid.setCellValue(row_index, col_index, '0',TYPE_DATA);	
	}
}
efgrid_onCellDisplayReady = function( div_node_html, row_index, col_index, col_value_c, display_value, grid_id )
{
  //多Grid时的检验
  if (grid_id != "ef_grid_result") return;
  var grid = efgrid.getGridObject( grid_id );
  if(!grid.getColumn(col_index, TYPE_DATA)) return;
  var columnEname = grid.getColumn(col_index, TYPE_DATA).getEname(); 
  switch (columnEname) { 
     case "fdIsStart":
         var html = "";
         if (display_value == "1"){
           html = "<div align=center><input hidefocus='-1' type='checkbox' checked onclick='setAuth("+row_index+","+col_index+",this.checked);'/></div>";
         } else {
           html = "<div align=center><input hidefocus='-1' type='checkbox' onclick='setAuth("+row_index+","+col_index+",this.checked)'/></div>";
         }
         return html;  
     case "fdIsThrough":
         var html = "";
         if (display_value == "1")html = "<div align=center><input hidefocus='-1' type='checkbox' checked /></div>";
         else html = "<div align=center><input hidefocus='-1' type='checkbox' /></div>";
         return html;  
         break;   
  }
}